package com.truyen.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.googlecode.ehcache.annotations.Cacheable;
import com.truyen.persistence.dao.ChapterTmpTruyenTinhCamDao;
import com.truyen.persistence.entity.ChapterTmpTruyenTinhCam;
import com.truyen.persistence.entity.TruyenTinhCam;
import com.truyen.service.ChapterTmpTruyenTinhCamService;
import com.truyen.utils.PagingInfo;


@Service
public class ChapterTmpTruyenTinhCamServiceImpl implements ChapterTmpTruyenTinhCamService {
	
	@Autowired
	private ChapterTmpTruyenTinhCamDao chapterTmpTruyenTinhCamDao;
	
	@Override
	public void save(ChapterTmpTruyenTinhCam entity) {
		chapterTmpTruyenTinhCamDao.save(entity);
	}

	@Override
	@Cacheable(cacheName="chapterTmpTruyenTinhCamByIdCacheDataController")
	public ChapterTmpTruyenTinhCam findById(Long id) {
		return chapterTmpTruyenTinhCamDao.findById(id);
	}

	@Override
	public List<ChapterTmpTruyenTinhCam> getAll() {
		return chapterTmpTruyenTinhCamDao.findAll();
	}

	@Override
	public ChapterTmpTruyenTinhCam findByProperty(String column, Object value) {
		List<ChapterTmpTruyenTinhCam> lst = chapterTmpTruyenTinhCamDao.findByQuery(column, value);
		return (lst.size() > 0)?lst.get(0):null;
	}

	@Override
	public List<ChapterTmpTruyenTinhCam> getLstChapterByTruyen(TruyenTinhCam entity, String kwSearch, String sort, String sortBy, PagingInfo pInfo) {
		return chapterTmpTruyenTinhCamDao.getLstChapterByTruyen(entity,kwSearch,sort,sortBy,pInfo);
	}

	@Override
	public ChapterTmpTruyenTinhCam findAliasvTruyen(TruyenTinhCam entity, String alias) {
		return chapterTmpTruyenTinhCamDao.findAliasvTruyen(entity, alias);
	}

	@Override
	@Cacheable(cacheName="chapterTmpTruyenTinhCamAllCacheDataController")
	public List<ChapterTmpTruyenTinhCam> getLstAllChapterTmpTruyenTinhCam(String kwSearch, String sort, String sortBy, PagingInfo pInfo) {
		return chapterTmpTruyenTinhCamDao.getLstAllChapterTmpTruyenTinhCam(kwSearch, sort, sortBy, pInfo);
	}

	@Override
	public void updateChapterNumber(Long id, float chapterNumberChange) {
		try{
			ChapterTmpTruyenTinhCam chapter = findById(id);
			chapter.setChapterNumber(chapterNumberChange);
			chapterTmpTruyenTinhCamDao.merge(chapter);
		}catch (Exception e) {
			// TODO: handle exception
		}
		
	}

	@Override
	@Cacheable(cacheName="chapterTmpTruyenTinhCamCacheTruyenController")
	public List<ChapterTmpTruyenTinhCam> getByTruyen(TruyenTinhCam entity) {
		return chapterTmpTruyenTinhCamDao.getByTruyen(entity);
	}

	@Override
	public ChapterTmpTruyenTinhCam getChapterByTruyenChapnumber(TruyenTinhCam entity, float chapterNumber) {
		return chapterTmpTruyenTinhCamDao.getChapterByTruyenChapnumber(entity,chapterNumber);
	}

	@Override
	@Transactional
	public void delete(long id) {
		try{
			ChapterTmpTruyenTinhCam chapter = findById(id);
			if(chapter != null){
				chapterTmpTruyenTinhCamDao.delete(chapter);
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
	}

	@Override
	@Cacheable(cacheName="chapterTmpTruyenTinhCamMoiCapNhatCacheTruyenController")
	public List<ChapterTmpTruyenTinhCam> getListNewChapter(int maxLimit) {
		return chapterTmpTruyenTinhCamDao.getListNewChapter(maxLimit);
	}
	
	@Override
	public void update(Long id, Float chapterNumber) {
		try{
			ChapterTmpTruyenTinhCam chapter = findById(id);
			if(chapter != null){
				chapter.setChapterNumber(chapterNumber);
				chapterTmpTruyenTinhCamDao.merge(chapter);
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
	}

	@Override
	public List<ChapterTmpTruyenTinhCam> getLstByOrderBy(String columnOrderBy, PagingInfo pInfo) {
		return chapterTmpTruyenTinhCamDao.getLstByOrderBy(columnOrderBy, pInfo);
	}

	@Override
	public List<ChapterTmpTruyenTinhCam> getByTruyenPaging(TruyenTinhCam entity, PagingInfo pInfoChapter) {
		return chapterTmpTruyenTinhCamDao.getByTruyenPaging(entity,pInfoChapter);
	}

	@Override
	public ChapterTmpTruyenTinhCam findByTruyenChapterNumber(TruyenTinhCam entity, float chapterNumber) {
		return chapterTmpTruyenTinhCamDao.findByTruyenChapterNumber(entity,chapterNumber);
	}

	@Override
	public List<Object> getByIdTruyen(Long idTruyen) {
		return chapterTmpTruyenTinhCamDao.getByIdTruyen(idTruyen);
	}

}
